//
//  NSString+Useful.m
//  KSLib
//
//  Created by User on 9/23/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "NSString+Useful.h"


@implementation NSString (NSString_Useful)

-(BOOL) isValidEmailAddress{
    
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; 
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    
    return [emailTest evaluateWithObject:self];
    
}

-(BOOL) isNumeric{
    
    NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithRange:NSMakeRange('0',10)] invertedSet];
    NSString *trimmed = [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    BOOL isNumeric = trimmed.length > 0 && [trimmed rangeOfCharacterFromSet:nonNumberSet].location == NSNotFound;
    
    return isNumeric;
}
    
@end
